<template>
  <div class="search">
    <!-- 1.输入搜索关键字的表单 -->
    <el-form :model="searchForm" ref="formRef" label-width="80px" size="large">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="社团名称" prop="clubName">
            <el-input
              v-model="searchForm.clubName"
              placeholder="输入要查询的社团名称"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="活动标题" prop="eventName">
            <el-input
              v-model="searchForm.eventName"
              placeholder="输入要查询的活动标题"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="状态" prop="status">
            <el-select
              v-model="searchForm.status"
              placeholder="请选择查询的状态"
              style="width: 100%"
            >
              <el-option label="进行中" value="ongoing" />
              <el-option label="未开始" value="approved" />
              <el-option label="已截止" value="finished" />
            </el-select> </el-form-item
        ></el-col>
      </el-row>
    </el-form>
    <!-- 2.重置和搜索的按钮 -->
    <div class="btns">
      <el-button icon="Refresh" @click="handleResetClick">重置</el-button>
      <el-button icon="Search" type="primary" @click="handleQueryClick"
        >查询</el-button
      >
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import type { ElForm } from 'element-plus'
const emit = defineEmits(['queryClick', 'resetClick'])
const searchForm = reactive({
  clubName: '',
  eventName: '',
  status: 'ongoing'
})
// 重置操作
const formRef = ref<InstanceType<typeof ElForm>>()
function handleResetClick() {
  formRef.value?.resetFields()

  // 2.将事件出去, content内部重新发送网络请求
  emit('resetClick')
}

function handleQueryClick() {
  emit('queryClick', searchForm)
}
</script>

<style lang="less" scoped>
.search {
  background-color: #fff;
  padding: 20px;

  .el-form-item {
    padding: 20px 30px;
    margin-bottom: 0;
  }

  .btns {
    text-align: right;
    padding: 0 50px 10px 0;

    .el-button {
      height: 36px;
    }
  }
}
</style>
